#!/usr/bin/env python

import pypvm
import sys
#from signal import signal, SIGTERM

#def sig_h (signum, traceback):
#    print "SLAVE: got signal", signum

try:
    #signal (SIGTERM, sig_h)
    parent = pypvm.parent()

# ============================ test recv() ===================================
    print "SLAVE: receiving data from tid %s..." % parent
    pypvm.recv(parent, 1)

# ============================ test up() =====================================
    print "SLAVE: unpacking data..."
    data = pypvm.upk()
    print "SLAVE: data received = %s" % data

# sending results to master...
    pypvm.initsend(pypvm.data['default'])
    print "SLAVE: sending data to master..."
    my_data = ['Pero vo so loco viteh', 'Jojojo']
    pypvm.pk(my_data)
    pypvm.send(parent, 2)

    print "SLAVE: exiting pvm..."
    pypvm.exit()

except:
    print "A pypvm error occured!"
    a =  sys.exc_info()
    print str(a[0])
    print a[1]
